from fastapi import Depends, Request, HTTPException
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials


def parse_token(credentials: HTTPAuthorizationCredentials = Depends(HTTPBearer())):
    return credentials.credentials


def parse_token_from_request(req: Request):

    auth_header = req.headers.get("Authorization")

    if auth_header is None:
        raise HTTPException(status_code=401, detail="Authorization header is missing")

    if not auth_header.startswith("Bearer "):
        raise HTTPException(status_code=401, detail="Invalid authorization header")

    return auth_header[7:]




